import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: GridViewStackExample(),
);
}
}
class GridViewStackExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GridView with Stack Example'),
),
body: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
),
itemCount: 4,
itemBuilder: (context, index) {
return Stack(
children: [
Container(
color: Colors.blue,
child: Center(
child: Text(
'Grid Item $index',
style: TextStyle(color: Colors.white),
),
),
),
Positioned(
top: 5,
left: 5,
child: Icon(
Icons.star,
color: Colors.yellow,
size: 30,
),
),
],
);
},
),
);
}
}